package com.review.reviewsb.controller;

import com.review.reviewsb.domain.User;
import com.review.reviewsb.service.UserService;
import com.review.reviewsb.utils.JsonData;
import jdk.nashorn.internal.parser.Token;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: reviewSb
 * @description: 用户控制器
 * @author: YaoZhiLi
 * @create: 2021-07-03 10:52
 */


@RestController
@RequestMapping("/api/v1/pub/user")
public class UserController {
    @Autowired
    private UserService userService;
   /* @PostMapping("login")
    public JsonData login(String name, String pwd){
        System.out.println(name+pwd);
        return JsonData.buildSuccess("");
    }*/
    @PostMapping("login")
    public JsonData login(@RequestBody User user){
        String login = userService.login(user.getName(), user.getPwd());
        return login!=null?JsonData.buildSuccess(login):JsonData.buildError("账号密码错误");
    }

    @GetMapping("listUser")
    public JsonData listUser(){
        List list = userService.listUser();
        return JsonData.buildSuccess(list);
    }

}